package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("新增购物")
    public Result<String> add(@RequestBody ShoppingCartDTO dto){
        log.info("新增购物：{}",dto);
        shoppingCartService.add(dto);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> queryCart(){
        log.info("查看购物车");
        List<ShoppingCart> shoppingCarts = shoppingCartService.queryCart();
        return Result.success(shoppingCarts);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result deleteShop(){
        log.info("清空购物车");
        shoppingCartService.deleteShop();
        return Result.success();
    }



}
